
#ifndef REALTIMETYPE_H_
#define REALTIMETYPE_H_

#include "Core.h"

namespace p2 {

typedef uint32 rttid;

/*
 * Ref: Martin Fischer fischer@graphics.cs.uni-bonn.de
 */
#define DECLARE_RTT(ClassName, BaseClass)		\
	public:	\
		static inline char const* TYPE() { return m_TYPE; }	\
		static inline rttid classId() { static rttid s_id = RealTimeType::createId(); return s_id; }	\
		virtual rttid Id() const { return classId(); }	\
		virtual bool isA(rttid id) const { return (id == classId()) || BaseClass::isA(id); }	\
		static inline ClassName* cast(BaseClass* rtt) { if (rtt->isA(ClassName::classId())) { return (ClassName*) rtt; } return 0; }	\
		static inline boost::fast_pool_allocator<ClassName>& getAllocator() { return _allocator; }	\
	private:	\
		static char const* m_TYPE;	\
		static rttid _rttid;	\
		static boost::fast_pool_allocator<ClassName> _allocator;

#define IMPLEMENT_RTT(Namespace, ClassName)	\
	char const* ClassName::m_TYPE = #Namespace"."#ClassName;	\
	rttid ClassName::_rttid = ClassName::createId();	\
	boost::fast_pool_allocator<ClassName> ClassName::_allocator;

class RealTimeType
{
public:
	virtual ~RealTimeType()
	{
	}
	static inline rttid createId()
	{
		static rttid id = 0;
		return id++;
	}
	static inline rttid classId()
	{
		static rttid s_id = createId();
		return s_id;
	}
	virtual rttid Id() const
	{
		return createId();
	}
	virtual bool isA(rttid id) const
	{
		return (id == classId());
	}
protected:
	RealTimeType()
	{
	}
};

}

#endif	//REALTIMETYPE_H_
